//
//  CHJPresentationController.swift
//  JIMWeiBo
//
//  Created by 陈恒均 on 2018/2/10.
//  Copyright © 2018年 陈恒均. All rights reserved.
//

import UIKit

class CHJPresentationController: UIPresentationController {
    // MARK:- 对外提供的属性
    var presentedFrame:CGRect = CGRect.zero
    
    
    private lazy var coverView : UIView = UIView()
    
    override func containerViewDidLayoutSubviews() {
        presentedView?.frame = presentedFrame
        
        
        setupCoverView()
        
    }
}

extension CHJPresentationController
{
    private func setupCoverView() {
        containerView?.insertSubview(coverView, at: 0)
        coverView.backgroundColor = UIColor(white: 0.8, alpha: 0.2)
        coverView.frame = containerView!.bounds
        let tapGes = UITapGestureRecognizer(target: self, action: #selector(CHJPresentationController.coverViewClick))
        coverView .addGestureRecognizer(tapGes)
        
    }
}
// MARK:- 事件监听
extension CHJPresentationController
{
    @objc private func coverViewClick() {
        presentedViewController.dismiss(animated: true, completion: nil)
    }
}
